package com.asom.player;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;

import com.asom.player.CustomActionBar.ShowSearchAction;
import com.asom.player.service.Player;
import com.markupartist.android.widget.ActionBar.AbstractAction;
import com.markupartist.android.widget.ActionBar.Action;

public class CustomActivity extends Activity {

	protected CustomActionBar actionBar;
	protected Action showSearch;

	protected Player player;

	@Override
	public void setContentView(int layoutResID) {

		super.setContentView(layoutResID);
		actionBar = (CustomActionBar) findViewById(R.id.actionbar);

		showSearch = new ShowSearchAction(actionBar);
		if (actionBar != null)
			actionBar.addAction(showSearch);
	}

	@Override
	protected void onResume() {

		super.onResume();
		// AdsHolder.putAdsHere(this, R.id.adsBottom); -- vom pune altceva:
		// player controls

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		/**
		 * Judecam daca avem ceva salvat in actionbar. exemplu: suntem in search
		 * mode.
		 */
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (actionBar.mSavedActions != null
					&& actionBar.mSavedActions.size() > 0) {
				actionBar.dismissInput();
				return true;
			}
		}
		/**
		 * Am ajuns aici, putem returna ce se returneaza normal
		 */
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.simple_menu, menu);

		menu.getItem(0).setIcon(R.drawable.ic_menu_notifications);
		menu.getItem(1).setIcon(android.R.drawable.ic_menu_help);
		menu.getItem(2).setIcon(android.R.drawable.ic_menu_preferences);
		return true;
	}

	// @Override
	// public boolean onPrepareOptionsMenu(Menu menu) {
	//
	// if (actionBar.mSavedActions != null
	// && actionBar.mSavedActions.size() > 0) {
	// actionBar.dismissInput();
	// }
	//
	// return super.onPrepareOptionsMenu(menu);
	// }

	protected class GoHomeAction extends AbstractAction {

		private Context mPackageContext;

		public GoHomeAction() {
			super(R.drawable.ic_title_home_default);
		}

		public GoHomeAction(Context packageContext) {
			super(R.drawable.ic_title_home_default);

			mPackageContext = packageContext;
		}

		@Override
		public void performAction(View view) {

			Intent categoryListToDashboard = new Intent(mPackageContext,
					DashboardActivity.class);
			startActivity(categoryListToDashboard);
		}
	}
}